<?php

class Admin_Controller_Base extends Zend_Controller_Action {
   
   protected function _setTitle($viewTitle, $headTitle=array()) {
   
      $view = Zend_Layout::getMvcInstance()->getView(); 
      $this->view->title = $view->translate->_($viewTitle);
      if(!is_array($headTitle) || !$headTitle) {
         $headTitle = array($viewTitle);
      }
      foreach($headTitle as $ht) {
         $this->view->headTitle($view->translate->_($ht));
      }
      $this->view->params = $this->getRequest()->getParams();
   }
   
   public function init() {
      $this->_helper->layout->setLayout('admin'); 
      $this->_setTitle('', 'Administrator');
   }
   
   protected function _setPaginator($table, $select=null) {
      $db = Zend_Registry::get('db');
      if(!$select) {
         $select = $db->select()
                      ->from(array('i' => $table));
         $sort = $this->_getParam('sort');
         if(strstr($sort, ':')) {
            $sort = explode(':', $sort);
            $sort = $sort[1];
         }
         $direction = $this->_getParam('direction');
         if(strstr($direction, ':')) {
            $direction = explode(':', $direction);
            $direction = $direction[1];
         }
         if($sort) {
            $orderBy = sprintf('%s %s', $sort, $direction);
            $select->order(array($orderBy));
         }
      }
      $paginator = Zend_Paginator::factory($select);
      $pagenum = $this->_getParam('page');
      $pagenum = ($pagenum != null ? $pagenum : 1);
      $paginator->setCurrentPageNumber($pagenum);
      Zend_View_Helper_PaginationControl::setDefaultViewPartial(
         'pagination_control.phtml'
      );
      //		$paginator->setView($view);
      $this->view->paginator = $paginator;

   }
   
}
